home *** CD-ROM | disk | FTP | other *** search
/ Amiga News 95 / Amiga News 95.iso / dpat / dpat33 / dice config / diceconfig.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-13  |  16.4 KB  |  527 lines

  1. /*****************************************************************************\
  2. *                                                                             *
  3. *                               DiceConfig                                    *
  4. *                                                                             *
  5. *                            (C) LF Soft 1992                                 *
  6. *                                                                             *
  7.  *****************************************************************************
  8. *                                                                             *
  9. *    Ce programme permet de configurer façilement DICE en sélèctionnant les   *
  10. *   options activées dans DCCOPTS. En plus des options standards, DiceConfig  *
  11. *   va chercher dans DLIB:DiceConfig.cfg les informations concernant les libs *
  12. *   que l'on peut utiliser. Le format de ce fichier est le suivant :          *
  13. *                                                                             *
  14. *       1er ligne : Commande qui doivent toujours faire partie de DCCOPTS     *
  15. *           par exemple -1.3 -f -ms -//                                       *
  16. *                                                                             *
  17. *        Suivent ensuite des groupes de 2 lignes dont la premiere indique le  *
  18. *       nom de la librairie, et la seconde les options a mettre dans DCCOPTS  *
  19. *                                                                             *
  20.  *****************************************************************************
  21. *                                                                             *
  22. *          Date       Version     Par        Remarques                        *
  23. *         ------     ---------   -----      -----------                       *
  24. *       02-Sep-1992     1.0     L.Faillie   Limite de 10 Librairies           *
  25. *                                           nom de 8 caracteres, & ligne d'   *
  26. *                                           options limitées a 80 caracteres  *
  27. *                                                                             *
  28.  *****************************************************************************
  29. *                                                                             *
  30. *   Note: Dice est © M.Dillon, mais DiceConfig est © LF Soft 1992.            *
  31. *       Ce programme est un FreeWare ( mais des contributions ne sont pas     *
  32. *       refusées ;-) ). Il utilise beaucoup de propriétés propre a DICE ce    *
  33. *       qui indique qu'il ne peut etre recompilé avec d'autres compilateurs.  *
  34. *       De plus certaines options comme -profx ou -unix ne sont disponibles   *
  35. *       qu'avec la version enregistré du compilateur.                         *
  36. *   Pour ceux qui regarde ce source : Non, auccune librairie  Amiga  n'est    *
  37. *        ouverte car DICE le fait tous seul !!                                *
  38. *                                                                             *
  39. *   Compillé & testé sur un Amiga 1000 sous WB & KS 1.3, 68010, 2Mo de RAMs   *
  40. *       & un disque dur de 52 Mo avec la version 2.06.40 R de Dice.           *
  41. *       Gadets créés par POWERSOURCE V3.0 & test avec CSH v5.19               *
  42. *                                                                             *
  43.  *****************************************************************************
  44. *                                                                             *
  45. *                      Laurent FAILLIE                                        *
  46. *                      " Les Vuardes "                                        *
  47. *                     74930 Pers-Jussy                                        *
  48. *                           FRANCE                                            *
  49. *                                                                             *
  50. \*****************************************************************************/
  51.  
  52. #include <exec/types.h>
  53. #include <stdio.h>
  54. #include <stdlib.h>
  55. #include <intuition/intuition.h>
  56. #include <graphics/gfxbase.h>
  57. // #include <LF.h>
  58.  
  59. #include <libraries/dos.h>
  60. #include <libraries/dosextens.h>
  61.  
  62. char exist(char *fn)
  63. {
  64.     struct FileLock *fl,*Lock();
  65.  
  66.     if(!(fl=Lock(fn,ACCESS_READ)))
  67.         return(0);
  68.  
  69.     UnLock(fl);
  70.     return(1);
  71. }
  72.  
  73. #include <stdio.h>
  74.  
  75. char *LFgets(FILE *f,char *l,size_t max)
  76. /* Lit une chaine & efface un eventuel \n */
  77. {
  78.     size_t i;
  79.  
  80.     fgets(l,max,f);
  81.     if (l[(i=strlen(l)-1)]=='\n') l[i]=0;
  82.     return(l);
  83. }
  84.  
  85.  
  86. // Messages d'erreurs
  87.  
  88. const char *w_conf[]={"\x1b[33mCan't find config file\x1b[0m",
  89.                       "\x1b[33mFichier de config absant\x1b[0m"},
  90.     *w_act[]={"Action line too long","ligne d'Action trops longue"},
  91.     *err_var[]={"Can't update variable","La variable ne peut pas etre mise a jour"},
  92.     *err_fntre[]={"Can't open window","Impossible d'ouvrir la fenetre"};
  93.  
  94. // Pour utiliser façilement les gadgets.
  95.  
  96. #define Val(x) ((((struct PropInfo*)((x).SpecialInfo))->VertPot)/0x3fff)
  97. #define SetVal(x,i) ((struct PropInfo*)((x).SpecialInfo))->VertPot = (i)*0x3fff
  98.  
  99. #define Sel(x) (((x).Flags & SELECTED) ? 1:0)
  100. #define SetSel(x,i) (x).Flags &=~SELECTED;(x).Flags |= ((i)?SELECTED:0)
  101.  
  102.  
  103. // Fichiers utilisés
  104.  
  105. #ifdef DEBUG
  106. #define CONFIGNAME "VD0:DiceConfig.cfg"
  107. #define DCCENV     "VD0:DCCOPTS"
  108. #else
  109. #define CONFIGNAME "DLIB:DiceConfig.cfg"
  110. #define DCCENV     "ENV:DCCOPTS"
  111. #endif
  112.  
  113.  
  114. // Définitions des variables de Configs, ceci permet de retrouver les memes
  115. // gadgets selectionnées lorsque le programme est relancé. Mieux que __shared
  116. // qui ne passe pas avec ARP.
  117.  
  118.     // define pour les gadgets.
  119. #define PURE        1
  120. #define UNIX        2
  121. #define DYNASTACK   4
  122. #define DBG         8
  123. #define LIBBASE     4
  124.  
  125. char *ConfigFile = "T:DiceConfig.config";
  126. long ConfigVersion = 1;
  127.  
  128. __config UBYTE prof=0; // Valeur du prof
  129. __config UWORD gad=0;  // Gadgets selectionnés
  130.  
  131.  
  132. // Definitions des gadgets ( Mis en tableau pour façilité la programmation )
  133.  
  134. /*---------------------------------------------------*
  135.   Gadgets created with PowerSource V3.0
  136.   which is (c) Copyright 1990-91 by Jaba Development
  137.   written by Jan van den Baard
  138.  *---------------------------------------------------*/
  139.  
  140. SHORT SharedBordersPairs0[] = {
  141.   0,0,0,14,1,13,1,0,80,0 };
  142. SHORT SharedBordersPairs1[] = {
  143.   1,14,80,14,80,1,81,0,81,14 };
  144. SHORT BorderprofP1[]={
  145.   0,0,0,102,1,101,1,0,82,0},
  146.       BorderprofP2[]={
  147.   1,102,82,102,82,1,83,0,83,102};
  148.  
  149. struct Border SharedBorders[] = {
  150.   0,0,1,0,JAM1,5,(SHORT *)&SharedBordersPairs0[0],&SharedBorders[1],
  151.   0,0,2,0,JAM1,5,(SHORT *)&SharedBordersPairs1[0],NULL },
  152.     Borderprof[] = {
  153.   0,0,1,0,JAM1,5,(SHORT *)&BorderprofP1[0],&Borderprof[1],
  154.   0,0,2,0,JAM1,5,(SHORT *)&BorderprofP2[0],NULL };
  155.  
  156.  
  157. struct TextAttr TOPAZ80 = {
  158.         (STRPTR)"topaz.font",
  159.         TOPAZ_EIGHTY,0,0
  160. };
  161.  
  162. struct IntuiText g_cancel_text = {
  163.   1,0,JAM2,20,4,&TOPAZ80,(UBYTE *)"CANCEL",NULL };
  164.  
  165. #define g_cancel_ID    16
  166.  
  167. struct Gadget g_cancel = {
  168.   NULL,299,128,82,15,
  169.   GADGHCOMP,
  170.   TOGGLESELECT+RELVERIFY,
  171.   BOOLGADGET,
  172.   (APTR)&SharedBorders[0],NULL,
  173.   &g_cancel_text,NULL,NULL,g_cancel_ID,NULL };
  174.  
  175. struct IntuiText g_ok_text = {
  176.   1,0,JAM2,30,4,&TOPAZ80,(UBYTE *)"OK",NULL };
  177.  
  178. #define g_ok_ID    15
  179.  
  180. struct Gadget g_ok = {
  181.   &g_cancel,77,128,82,15,
  182.   GADGHCOMP,
  183.   TOGGLESELECT+RELVERIFY,
  184.   BOOLGADGET,
  185.   (APTR)&SharedBorders[0],NULL,
  186.   &g_ok_text,NULL,NULL,g_ok_ID,NULL };
  187.  
  188. #define g_lib9_ID    14
  189. #define g_lib8_ID    13
  190. #define g_lib7_ID    12
  191. #define g_lib6_ID    11
  192. #define g_lib5_ID    10
  193. #define g_lib4_ID    9
  194. #define g_lib3_ID    8
  195. #define g_lib2_ID    7
  196. #define g_lib1_ID    6
  197. #define g_lib0_ID    5
  198.  
  199. // Tableau comportant les librairies
  200.  
  201. char lib[10][8], // Text affiché
  202.      liba[10][80]; // action sur DCCOPTS
  203.  
  204. struct IntuiText
  205.     g_lib_titre = { 1,0,JAM1,52,-11,&TOPAZ80,(UBYTE *)"Libraries",NULL},
  206.     g_lib_txt[]={
  207.         3,0,JAM1,14,4,&TOPAZ80,(UBYTE *)lib[0],&g_lib_titre,
  208.         3,0,JAM1,14,4,&TOPAZ80,(UBYTE *)lib[1],NULL,
  209.         3,0,JAM1,14,4,&TOPAZ80,(UBYTE *)lib[2],NULL,
  210.         3,0,JAM1,14,4,&TOPAZ80,(UBYTE *)lib[3],NULL,
  211.         3,0,JAM1,14,4,&TOPAZ80,(UBYTE *)lib[4],NULL,
  212.         3,0,JAM1,14,4,&TOPAZ80,(UBYTE *)lib[5],NULL,
  213.         3,0,JAM1,14,4,&TOPAZ80,(UBYTE *)lib[6],NULL,
  214.         3,0,JAM1,14,4,&TOPAZ80,(UBYTE *)lib[7],NULL,
  215.         3,0,JAM1,14,4,&TOPAZ80,(UBYTE *)lib[8],NULL,
  216.         3,0,JAM1,14,4,&TOPAZ80,(UBYTE *)lib[9],NULL
  217.     };
  218.  
  219. struct Gadget g_lib[] ={
  220.  {
  221.   &g_lib[1],237,25,82,15,
  222.   GADGHCOMP,
  223.   TOGGLESELECT+RELVERIFY,
  224.   BOOLGADGET,
  225.   (APTR)&SharedBorders[0],NULL,
  226.   &g_lib_txt[0],NULL,NULL,g_lib0_ID,NULL
  227.  },{
  228.   &g_lib[2],323,25,82,15,
  229. GADGHCOMP,
  230.   TOGGLESELECT+RELVERIFY,
  231.   BOOLGADGET,
  232.   (APTR)&SharedBorders[0],NULL,
  233.   &g_lib_txt[1],NULL,NULL,g_lib1_ID,NULL
  234.  },{
  235.   &g_lib[3],237,42,82,15,
  236. GADGHCOMP,
  237.   TOGGLESELECT+RELVERIFY,
  238.   BOOLGADGET,
  239.   (APTR)&SharedBorders[0],NULL,
  240.   &g_lib_txt[2],NULL,NULL,g_lib2_ID,NULL
  241.  },{
  242.   &g_lib[4],323,42,82,15,
  243. GADGHCOMP,
  244.   TOGGLESELECT+RELVERIFY,
  245.   BOOLGADGET,
  246.   (APTR)&SharedBorders[0],NULL,
  247.   &g_lib_txt[3],NULL,NULL,g_lib3_ID,NULL
  248.  },{
  249.   &g_lib[5],237,59,82,15,
  250. GADGHCOMP,
  251.   TOGGLESELECT+RELVERIFY,
  252.   BOOLGADGET,
  253.   (APTR)&SharedBorders[0],NULL,
  254.   &g_lib_txt[4],NULL,NULL,g_lib4_ID,NULL
  255.  },{
  256.   &g_lib[6],323,59,82,15,
  257. GADGHCOMP,
  258.   TOGGLESELECT+RELVERIFY,
  259.   BOOLGADGET,
  260.   (APTR)&SharedBorders[0],NULL,
  261.   &g_lib_txt[5],NULL,NULL,g_lib5_ID,NULL
  262.  },{
  263.   &g_lib[7],237,76,82,15,
  264. GADGHCOMP,
  265.   TOGGLESELECT+RELVERIFY,
  266.   BOOLGADGET,
  267.   (APTR)&SharedBorders[0],NULL,
  268.   &g_lib_txt[6],NULL,NULL,g_lib6_ID,NULL
  269.  },{
  270.   &g_lib[8],323,76,82,15,
  271. GADGHCOMP,
  272.   TOGGLESELECT+RELVERIFY,
  273.   BOOLGADGET,
  274.   (APTR)&SharedBorders[0],NULL,
  275.   &g_lib_txt[7],NULL,NULL,g_lib7_ID,NULL
  276.  },{
  277.   &g_lib[9],237,93,82,15,
  278. GADGHCOMP,
  279.   TOGGLESELECT+RELVERIFY,
  280.   BOOLGADGET,
  281.   (APTR)&SharedBorders[0],NULL,
  282.   &g_lib_txt[8],NULL,NULL,g_lib8_ID,NULL
  283.  },{
  284.   &g_ok,323,93,82,15,
  285. GADGHCOMP,
  286.   TOGGLESELECT+RELVERIFY,
  287.   BOOLGADGET,
  288.   (APTR)&SharedBorders[0],NULL,
  289.   &g_lib_txt[9],NULL,NULL,g_lib9_ID,NULL
  290.  }
  291. };
  292.  
  293. struct IntuiText g_debug_text = {
  294.   3,0,JAM1,21,3,&TOPAZ80,(UBYTE *)"Debug",NULL };
  295.  
  296. #define g_debug_ID    4
  297.  
  298. struct Gadget g_debug = {
  299.   &g_lib[0],114,95,82,15,
  300.   GADGHCOMP,
  301.   TOGGLESELECT+RELVERIFY,
  302.   BOOLGADGET,
  303.   (APTR)&SharedBorders[0],NULL,
  304.   &g_debug_text,NULL,NULL,g_debug_ID,NULL };
  305.  
  306. struct IntuiText g_dynastack_text = {
  307.   3,0,JAM1,5,4,&TOPAZ80,(UBYTE *)"DynaStack",NULL };
  308.  
  309. #define g_dynastack_ID    3
  310.  
  311. struct Gadget g_dynastack = {
  312.   &g_debug,114,71,82,15,
  313.   GADGHCOMP,
  314.   TOGGLESELECT+RELVERIFY,
  315.   BOOLGADGET,
  316.   (APTR)&SharedBorders[0],NULL,
  317.   &g_dynastack_text,NULL,NULL,g_dynastack_ID,NULL };
  318.  
  319. struct IntuiText g_unix_text = {
  320.   3,0,JAM1,24,4,&TOPAZ80,(UBYTE *)"Unix",NULL };
  321.  
  322. #define g_unix_ID    2
  323.  
  324. struct Gadget g_unix = {
  325.   &g_dynastack,113,47,82,15,
  326.   GADGHCOMP,
  327.   TOGGLESELECT+RELVERIFY,
  328.   BOOLGADGET,
  329.   (APTR)&SharedBorders[0],NULL,
  330.   &g_unix_text,NULL,NULL,g_unix_ID,NULL };
  331.  
  332. struct IntuiText g_pure_text = {
  333.   3,0,JAM1,26,3,&TOPAZ80,(UBYTE *)"Pure",NULL };
  334.  
  335. #define g_pure_ID    1
  336.  
  337. struct Gadget g_pure = {
  338.   &g_unix,113,24,82,15,
  339.   GADGHCOMP,
  340.   TOGGLESELECT+RELVERIFY,
  341.   BOOLGADGET,
  342.   (APTR)&SharedBorders[0],NULL,
  343.   &g_pure_text,NULL,NULL,g_pure_ID,NULL };
  344.  
  345. struct PropInfo g_prof_info = {
  346.   AUTOKNOB+FREEVERT,0x0000,0x0000,0xFFFF,0x3333,0,0,0,0,0,0 };
  347.  
  348. struct Image g_prof_image;
  349.  
  350. struct IntuiText g_prof_text[] = {
  351.   3,0,JAM1,-39,26,&TOPAZ80,(UBYTE *)"Prof",&g_prof_text[1],
  352.   3,0,JAM1,-38,5,&TOPAZ80,(UBYTE *)"None",&g_prof_text[2],
  353.   3,0,JAM1,-43,46,&TOPAZ80,(UBYTE *)"Prof1",&g_prof_text[3],
  354.   3,0,JAM1,-43,64,&TOPAZ80,(UBYTE *)"Prof2",&g_prof_text[4],
  355.   3,0,JAM1,-43,83,&TOPAZ80,(UBYTE *)"Prof3",NULL };
  356.  
  357. #define g_prof_ID    0
  358.  
  359. struct Gadget g_prof = {
  360.   &g_pure,59,24,26,97,
  361.   GADGHCOMP,
  362.   RELVERIFY,
  363.   PROPGADGET,
  364.   (APTR)&g_prof_image,NULL,
  365.   &g_prof_text[0],NULL,(APTR)&g_prof_info,g_prof_ID,NULL };
  366.  
  367. struct NewWindow nwin = {
  368.   98,36,437,151,0,1,
  369.   GADGETDOWN+GADGETUP+CLOSEWINDOW,
  370.   WINDOWDRAG+WINDOWDEPTH+NOCAREREFRESH+SMART_REFRESH+ACTIVATE,
  371.   &g_prof,NULL,
  372.   (UBYTE *)"Dice config V1.0 © LF Soft 1992",NULL,NULL,
  373.   150,50,640,262,WBENCHSCREEN };
  374.  
  375.  
  376. #define NEWWINDOW   &nwin
  377. #define WDBACKFILL  0
  378. #define FIRSTGADGET &g_prof
  379.  
  380.  
  381. struct IntuiMessage *Message = NULL;
  382. struct Window *window=NULL;
  383. FILE *f=NULL;
  384. UBYTE lang=0;
  385.  
  386. void by(){
  387.     if(f) fclose(f);f=NULL;
  388.     if (window)
  389.             CloseWindow(window);
  390. }
  391.  
  392. void Fatal(char *msg)
  393. {
  394.     char buff[100];
  395.  
  396.     buff[0]=0;buff[1]=50;buff[2]=17;
  397.     strcpy(&buff[3],msg);
  398.     buff[4+strlen(msg)]=0;
  399.     DisplayAlert(RECOVERY_ALERT,buff,30);
  400.     exit(15);
  401. }
  402.  
  403. void main(){
  404.     short NuGadg;
  405.     long class;
  406.     char l[256],defa[256],*var;
  407.  
  408.     if(var=getenv("Lang")){
  409.         if(!stricmp(var,"Français"))
  410.             lang=1;
  411.     }
  412.  
  413.     if((window = (struct Window *)
  414.         OpenWindow(NEWWINDOW))==0)
  415.             Fatal(err_fntre[lang]);
  416.  
  417.     atexit(by);
  418.  
  419.     for(NuGadg=0;NuGadg<10;NuGadg++)        // Si init direct, les gadgets
  420.         g_lib[NuGadg].Flags |=GADGDISABLED; // sont mal dessinés
  421.  
  422.     if(f=fopen(CONFIGNAME,"r")){
  423.         LFgets(f,defa,255); // Lecture des commandes par defaut
  424.         if(feof(f))
  425.             *defa=0;
  426.         else {
  427.             for(NuGadg=0;NuGadg<10;NuGadg++){
  428.                 LFgets(f,l,255); // Lecture du texte
  429.                 strncpy(lib[NuGadg],l,7);
  430.                 lib[NuGadg][7]=0;
  431.                 LFgets(f,l,255); // Lecture de l'actions
  432.                 if(strlen(l)>79)
  433.                     printf("\x1b[33m%s (lib %d)\x1b[0m\n",w_act[lang],NuGadg+1);
  434.                 strncpy(liba[NuGadg],l,79);
  435.                 liba[NuGadg][79]=0;
  436.                 if(feof(f)){
  437.                     *lib[NuGadg]=0;
  438.                     break;
  439.                 } else
  440.                     g_lib[NuGadg].Flags &=~GADGDISABLED;
  441.             }
  442.         }
  443.         fclose(f);f=NULL;
  444.     } else
  445.         puts(w_conf[lang]);
  446.  
  447.     DrawBorder(window->RPort,&Borderprof[0],9,21);
  448.  
  449.     // Selectionne les gadgets suivant la config
  450.     SetVal(g_prof,prof);
  451.     SetSel(g_pure,gad & PURE);
  452.     SetSel(g_unix,gad & UNIX);
  453.     SetSel(g_dynastack,gad & DYNASTACK);
  454.     SetSel(g_debug,gad & DBG);
  455.     for(NuGadg=0;NuGadg<10;NuGadg++){
  456.         if(g_lib[NuGadg].Flags & GADGDISABLED)
  457.             break;
  458.         SetSel(g_lib[NuGadg],gad & (1<<(LIBBASE+NuGadg)));
  459.     }
  460.     if(!exist(DCCENV))
  461.         g_cancel.Flags |= GADGDISABLED;
  462.  
  463.     RefreshGadgets(&g_prof,window,NULL);
  464.  
  465.     FOREVER{
  466.         Wait(1L << window->UserPort->mp_SigBit);
  467.         while(Message = (struct IntuiMessage *)GetMsg(window->UserPort)) {
  468.             NuGadg=((struct Gadget *)Message->IAddress)->GadgetID;
  469.             class=Message->Class;
  470.             ReplyMsg(Message);
  471.             if(class==GADGETUP)
  472.                 switch (NuGadg){
  473.                     case g_prof_ID:
  474.                         SetVal(g_prof,Val(g_prof));
  475.                         RefreshGList(&g_prof,window,NULL,1);
  476.     #ifdef DEBUG
  477.                         printf("%d\n",Val(g_prof));
  478.     #endif
  479.                         break;
  480.                     case g_cancel_ID:
  481.                         exit(0);
  482.                     case g_ok_ID:
  483.             // Sauvegarde de la config & mise a jour de la variable
  484.                         if(!(f=fopen(DCCENV,"w")))
  485.                             Fatal(err_var[lang]);
  486.                         fprintf(f,"%s ",defa);
  487.                         switch(prof=Val(g_prof)){
  488.                         case 1:
  489.                             fputs("-prof ",f);break;
  490.                         case 2:
  491.                             fputs("-prof1 ",f);break;
  492.                         case 3:
  493.                             fputs("-prof2 ",f);break;
  494.                         case 4:
  495.                             fputs("-prof3 ",f);break;
  496.                         }
  497.                         if(Sel(g_pure)){
  498.                              gad = PURE;
  499.                              fputs("-r ",f);
  500.                         } else
  501.                             gad = 0;
  502.                         if(Sel(g_unix)){
  503.                             gad |= UNIX;
  504.                             fputs("-unix ",f);
  505.                         }
  506.                         if(Sel(g_dynastack)){
  507.                             gad |= DYNASTACK;
  508.                             fputs("-gs ",f);
  509.                         }
  510.                         if(Sel(g_debug)){
  511.                             gad |= DBG;
  512.                             fputs("-DDEBUG -s ",f);
  513.                         }
  514.                         for(NuGadg=0;NuGadg<10;NuGadg++)
  515.                             if(Sel(g_lib[NuGadg])){
  516.                                 gad |= 1<<(LIBBASE+NuGadg);
  517.                                 fprintf(f,"%s ",liba[NuGadg]);
  518.                             }
  519.     #ifdef DEBUG
  520.                         printf("Config :%d, %x\n",prof,gad);
  521.     #endif
  522.                         exit(0);
  523.                 }
  524.         }
  525.     }
  526. }
  527.